package be.vdab.Servlets;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import be.vdab.dao.ReadSqlDAO;
import be.vdab.entities.Member;
import be.vdab.entities.Reservatie;
import be.vdab.util.GelukteMislukteVoorstellingen;


/**
 * Servlet implementation class OverzichtServlet
 */
@WebServlet("/overzicht.htm")
public class OverzichtServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String VIEW = "/WEB-INF/JSP/overzicht.jsp";  
	private ReadSqlDAO sqlDAO = new ReadSqlDAO();
	
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	HttpSession session = request.getSession();
    	@SuppressWarnings("unchecked")
		Map<Integer, Integer> reservatieMap = (HashMap<Integer, Integer>) session.getAttribute("reservatieMap");
    	
    	Member member = (Member) session.getAttribute("member");
		int klantNummer = (int) member.getKlantNr();
		
		GelukteMislukteVoorstellingen alleVoorstellingen = sqlDAO.reserveer(reservatieMap, klantNummer);
		List<Reservatie> gelukteReserveringen = alleVoorstellingen.getGelukteReserveringen();
		List<Reservatie> mislukteReserveringen = alleVoorstellingen.getMislukteReserveringen();
		
		
		session.setAttribute("gelukteReserveringen", gelukteReserveringen);
		session.setAttribute("mislukteReserveringen", mislukteReserveringen);
		
		session.setAttribute("destroy", "destroy");
		
		
    	RequestDispatcher dispatcher = request.getRequestDispatcher(VIEW);
	    dispatcher.forward(request, response);	
	}

   

}
